package cn.itcast.dubbo.service.impl;

import cn.itcast.dubbo.common.ReadOnly;
import cn.itcast.dubbo.mapper.GoodsMapper;
import cn.itcast.dubbo.mapper.WarehouseMapper;
import cn.itcast.dubbo.pojo.PageInfo;
import cn.itcast.dubbo.pojo.Warehouse;
import cn.itcast.dubbo.service.WarehouseService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @author .
 * created in 2020/1/16 18:38
 */

@Service(version = "${dubbo.service.version}")
public class WarehouseServiceImpl implements WarehouseService {
    @Resource
    private GoodsMapper goodsMapper;
    @Resource
    private WarehouseMapper warehouseMapper;

    @Override
    public int addWarehouse(Warehouse warehouse) {
        return warehouseMapper.addWarehouse(warehouse);
    }
    @ReadOnly
    @Override
    public PageInfo<Warehouse> findAllWarehouseByPage(PageInfo<Warehouse> info, String id) {
        if (StringUtils.isEmpty(id)) {
            id = null;
        }
        info.setCount(warehouseMapper.getAllWarehouseCount(id));
        info.setData(warehouseMapper.findAllByPage((info.getPage() - 1) * info.getLimit(), info.getLimit(), id));
        return info;
    }

}
